function funcUrlDel(names) {
  if (typeof (names) == 'string') {
    names = [names];
  }

  let loca = window.location;
  let obj = {}
  let arr: any = loca.search.substr(1).split("&");
  //获取参数转换为object
  for (let i = 0; i < arr.length; i++) {
    arr[i] = arr[i].split("=");
    obj[arr[i][0]] = arr[i][1];
  }
  //删除指定参数
  for (let i = 0; i < names.length; i++) {
    delete obj[names[i]];
  }
  //重新拼接url
  let url = loca.origin + loca.pathname + "?" + JSON.stringify(obj).replace(/[\"\{\}]/g, "").replace(/\:/g, "=").replace(/\,/g, "&");
  return url;
}

//  query之前传送过来就有参数为undefined,此处只过滤下不等于query的数据。,
//  此方法只删除url上token，重新进行渲染页面
export default function copyURL(query: any, status: string) {
  const oldToken = localStorage.getItem("token");
  let urls = window.location.pathname;
  if (query.T) {
    localStorage.setItem("token", query.T);
    let url = funcUrlDel(['T', 'admin_token']);
    history.pushState({}, "", url);//修改url查询参数不重新加载页面
    // window.open(urls, "_self");
  } else if (!query.T && !oldToken && status === 'portal') {
    if (!(urls.indexOf("login") > -1) && !(window.location.hash.endsWith("/oauth"))) {
      let url = funcUrlDel('');
      localStorage.setItem("copy_link_url_path", url);
    }
  }
}
